HA$PBExportHeader$w_ctacob_agrupar.srw
forward
global type w_ctacob_agrupar from window
end type
type uo_toolbarstrip2 from u_cst_toolbarstrip within w_ctacob_agrupar
end type
type uo_toolbarstrip from u_cst_toolbarstrip within w_ctacob_agrupar
end type
type dw_2 from datawindow within w_ctacob_agrupar
end type
type dw_1 from datawindow within w_ctacob_agrupar
end type
end forward

global type w_ctacob_agrupar from window
integer width = 2994
integer height = 1996
boolean titlebar = true
string title = "AGRUPAR DOCUMENTOS"
boolean controlmenu = true
windowtype windowtype = popup!
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
windowanimationstyle closeanimation = fadeanimation!
event ue_grabar ( )
event ue_adddocu ( )
event ue_addpago ( )
event ue_total ( )
uo_toolbarstrip2 uo_toolbarstrip2
uo_toolbarstrip uo_toolbarstrip
dw_2 dw_2
dw_1 dw_1
end type
global w_ctacob_agrupar w_ctacob_agrupar

type variables
u_cst_grid_ctaxcobrar iuo_ctacob
userobject iuo_ctaxcobrar
s_parm istr_parm
boolean ib_save=false
long il_id
double id_sald=0
end variables
forward prototypes
public function integer wf_valida ()
public function integer wf_ccid ()
end prototypes

event ue_grabar();string ls_sql

dw_1.accepttext()
dw_2.accepttext()

//long li_columna

//for li_columna = 1 to long(dw_1.Object.Datawindow.Column.Count)
//Messagebox('Columna', 'C('+String(li_Columna)+') Nombre:'+String(dw_1.Describe('#'+String(li_Columna)+'.Name'))+' Tipo:'+String(dw_1.Describe('#'+String(li_Columna)+'.Type'))+' Dato:'+String(dw_1.Object.Data[1, li_columna])) 
//next
//return

if wf_valida() = -1 then return
if wf_ccid() = -1 then return

if dw_1.update(true,false) = 1 then
	if dw_2.update(true,false) = 1 then
		
		ls_sql = 'cc_usp_save ' + string(il_id)
		execute immediate :ls_sql;
		ib_save=true
		commit;
		
//		iuo_ctaxcobrar.Dynamic Event ue_refrescar()
		f_msg('Datos grabados.', 4)
		close(this)
	else
		rollback; f_msg('No se puede grabar', 3)
	end if
else
	rollback; f_msg('No se puede grabar', 3)
end if

end event

event ue_adddocu();iuo_ctaxcobrar.Dynamic Event ue_agregar(1)

event ue_total()

end event

event ue_addpago();long ll_fila, ll_clie
String ls_ruc, ls_nomb
int li_mone
if wf_valida() = -1 then return
dw_1.scrolltorow(dw_1.insertrow(0))
if dw_2.rowcount() = 0 then return
li_mone = dw_2.object.idmoneda[1]
dw_1.object.idmoneda[dw_1.getrow()] = li_mone
dw_1.object.idUser  [dw_1.getrow()] = gs_idUser
dw_1.object.tStat   [dw_1.getrow()] = 'P'
dw_1.object.tCd     [dw_1.getrow()] = 'D'
ll_clie = dw_2.object.idClie[1]
dw_1.object.idClie[dw_1.getrow()] = ll_clie
select tRuc, tRazonSocial into :ls_ruc, :ls_nomb from dbo.MCLIENTE where idClie = :ll_clie;

dw_1.object.tRuc  [dw_1.getrow()] = ls_ruc
dw_1.object.cliente.text = ls_nomb

if li_mone = 1 then
	dw_1.object.ntipocambio[dw_1.getrow()] = 1
end if

event ue_total()
end event

event ue_total();long ll_fila
double ld_mont=0

for ll_fila = 1 to dw_2.rowcount()
	ld_mont = ld_mont + dw_2.object.nmonto[ll_fila]
next

dw_1.object.ntotal[dw_1.getrow()] = ld_mont
end event

public function integer wf_valida ();long        ll_row      //Almacena la fila en donde se encuentra el campo con valor null.
integer     li_columna  //Almacena el numero de columna con valor null.
string      ls_colname  //Almacena el nombre de la columna con valor null.
string      ls_columna  //Almacena el mensaje de validaci$$HEX1$$f300$$ENDHEX$$n de la columna.


//dw_1.AcceptText()

ll_row=1
li_columna = 0

dw_1.FindRequired(Primary!,ll_row, li_columna,ls_colname, True)

IF ll_row <> 0 THEN
	dw_1.SetColumn(li_columna)
	dw_1.ScrollToRow(ll_row)

	//Obtenemos el mensaje de validaci$$HEX1$$f300$$ENDHEX$$n obtenido.
	ls_columna= dw_1.describe(ls_colname+'.ValidationMsg')

	//Quitamos las comillas del mensaje de validaci$$HEX1$$f300$$ENDHEX$$n.
	ls_columna=left(ls_columna,len(ls_columna)-1)
	ls_columna=mid(ls_columna,2,len(ls_columna))
  
	dw_1.SetFocus()
  
	//Mostramos el mensaje de validaci$$HEX1$$f300$$ENDHEX$$n.
//	messagebox("Verifique",ls_columna,Exclamation!)
	return -1
end if
return 1
end function

public function integer wf_ccid ();long ll_fila

il_id = f_CCID()

dw_1.object.idProceso[dw_1.getrow()] = il_id
dw_1.object.nSaldo   [dw_1.getrow()] = dw_1.object.nTotal[dw_1.getrow()]

for ll_fila = 1 to dw_2.rowcount()
	/* ASIGNA EL ID */
	dw_2.object.idProceso[ll_fila] = il_id
	
	dw_2.object.fProceso    [ll_fila] = today()
	dw_2.object.idDocud     [ll_fila] = dw_1.object.idDocu  [dw_1.getrow()]
	dw_2.object.tDocumentod [ll_fila] = dw_1.object.tDocumento[dw_1.getrow()]
	dw_2.object.idMonedad   [ll_fila] = dw_1.object.idMoneda[dw_1.getrow()]
	dw_2.object.fEmisiond   [ll_fila] = dw_1.object.fEmision[dw_1.getrow()]
	dw_2.object.fVencd      [ll_fila] = dw_1.object.fVenc   [dw_1.getrow()]
	dw_2.object.nTipoCambiod[ll_fila] = dw_1.object.nTipoCambio[dw_1.getrow()]
	dw_2.object.tDh         [ll_fila] = 'D'
Next

return 1
end function

on w_ctacob_agrupar.create
this.uo_toolbarstrip2=create uo_toolbarstrip2
this.uo_toolbarstrip=create uo_toolbarstrip
this.dw_2=create dw_2
this.dw_1=create dw_1
this.Control[]={this.uo_toolbarstrip2,&
this.uo_toolbarstrip,&
this.dw_2,&
this.dw_1}
end on

on w_ctacob_agrupar.destroy
destroy(this.uo_toolbarstrip2)
destroy(this.uo_toolbarstrip)
destroy(this.dw_2)
destroy(this.dw_1)
end on

event resize;uo_toolbarstrip.Width = THIS.WorkSpaceWidth() - 12
uo_toolbarstrip2.Width = THIS.WorkSpaceWidth() - 12
dw_1.Width = THIS.WorkSpaceWidth() - 12
dw_2.Width = THIS.WorkSpaceWidth() - 12
end event

event open;istr_parm      = message.powerobjectparm

iuo_ctaxcobrar = istr_parm.auo_userobject

dw_1.settransobject(sqlca)
dw_2.settransobject(sqlca)
dw_1.setrowfocusindicator(hand!)
dw_2.setrowfocusindicator(hand!)


end event

event close;//f_msg(string(ib_save), 4)

iuo_ctaxcobrar.Dynamic Event ue_refrescar()
end event

type uo_toolbarstrip2 from u_cst_toolbarstrip within w_ctacob_agrupar
integer y = 700
integer width = 2638
integer taborder = 40
end type

event constructor;call super::constructor;//this.of_AddItem('Grabar','Save!','Grabar datos')
//this.of_AddSeparator()
//this.of_AddItem('Nuevo pago','New!','Agregar un cargo/abono')
//this.of_AddItem('Quitar pago','Hand!','Quitar un pago')
//this.of_AddSeparator()
this.of_AddItem('Agregar documento','Insert!','Agregar documento')
this.of_AddItem('Quitar documento','DeleteWatch5!','Quitar documento')
//this.of_AddSeparator()
//this.of_AddItem('Cerrar','Exit!','Cerrar agrupacion')

of_DisplayRaisedBorder(TRUE)
this.of_DisplayText(true)
end event

event ue_buttonclicked;call super::ue_buttonclicked;choose case Upper(as_button)
	case 'AGREGAR DOCUMENTO' 
		event ue_adddocu()
	CASE 'QUITAR DOCUMENTO'
		
end choose

end event

on uo_toolbarstrip2.destroy
call u_cst_toolbarstrip::destroy
end on

type uo_toolbarstrip from u_cst_toolbarstrip within w_ctacob_agrupar
integer width = 2629
integer taborder = 30
end type

on uo_toolbarstrip.destroy
call u_cst_toolbarstrip::destroy
end on

event constructor;call super::constructor;this.of_AddItem('Grabar','Save!','Grabar datos')

this.of_AddSeparator()
this.of_AddItem('Nuevo pago','New!','Agregar un cargo/abono')
this.of_AddItem('Quitar pago','Hand!','Quitar un pago')

this.of_AddSeparator()
this.of_AddItem('Cerrar','Exit!','Cerrar agrupacion')

of_DisplayRaisedBorder(TRUE)
this.of_DisplayText(true)
end event

event ue_buttonclicked;call super::ue_buttonclicked;choose case Upper(as_button)
	case 'GRABAR' 
		event ue_grabar()
	CASE 'NUEVO PAGO'
		event ue_addpago()
	CASE 'QUITAR PAGO'
		
	CASE 'CERRAR'	
		if F_MSG('Esta seguro que cerrar la ventana?',2)=2 then return
		Close(Parent)
end choose


end event

type dw_2 from datawindow within w_ctacob_agrupar
event ue_post ( )
event type integer ue_validar ( )
integer x = 9
integer y = 812
integer width = 2949
integer height = 1084
integer taborder = 20
string title = "none"
string dataobject = "d_ccdocuD"
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event ue_post();object.nmonto[getrow()] = object.nsaldo[getrow()]
end event

event type integer ue_validar();double ld_sald, ld_mont
ld_sald = object.nsaldo[getrow()]
ld_mont = object.nmonto[getrow()]
if String(ld_mont) <> string(ld_sald) then
	f_msj('El monto ingresado no puede ser mayor al saldo del documento.', 4)
	this.post event ue_post()
	return -1
end if

return 1
end event

event itemfocuschanged;if dwo.name = 'nmonto' then
	SelectText(1, Len(GetText()))
	setfocus()
end if

end event

event itemchanged;double ld_sald, ld_mont

if dwo.name = 'nmonto' then
//	this.event ue_validar()
end if
end event

type dw_1 from datawindow within w_ctacob_agrupar
event ue_enter pbm_dwnprocessenter
event ue_tecla pbm_dwnkey
integer x = 9
integer y = 108
integer width = 2725
integer height = 588
integer taborder = 10
string title = "none"
string dataobject = "d_ccdocu"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event ue_enter;Send( Handle( this ), 256, 9, Long( 0, 0 ) ) // Send message for processing TAB key 
return 1 
end event

event ue_tecla;double ld_total
if key = keyenter! then
	if getcolumnname() = 'ntotal' then
//		f_msg('Total', 4)
		ld_total = object.nTotal[getrow()]
	end if
end if

end event

event itemfocuschanged;//if dwo.name = 'nmonto' then
////	SelectText(1, Len(GetText()))
//	f_msg('', 1)
//end if
end event

event getfocus;//if dwo.name = 'nmonto' then
//scrolltorow(getrow())
	SelectText(1, Len(GetText()))
	setfocus()
//	f_msg('', 1)
//end if
end event

